<?php

	class NavigationView {
		
		private $_activeController = "activeController";
		private $_activeTopic = "activeTopic";
		private $_activeCategory = "activeCategory";
		private $_activePost = "activePost";
		private $_deletePost = "deletePost";
		private $_editPost = "editPost";
		private $_activePage = "activepage";
		private $_topicToEdit = "topicToEdit";
		private $_activePM = "activePM";
		private $_writePM = "writePM";
		
		//Creates link to the register page
		//Returns xhtml string
		public function DoRegisterLink(){
			return "<div class=button><a href='index.php?$this->_activeController=Register'>Register new user<a/></div>";		
		}
		
		//Creates link for returning to the login form
		//Returns xhtml string
		public function DoBackToLoginLink(){
			return "<div class=button><a href='index.php?$this->_activeController=Login'>Return to login<a/></div>";	
		}
		
		//Returns true if the activeController is Register
		public function IsRegisterControllerActive(){
			if(isset($_GET[$this->_activeController]) && $_GET[$this->_activeController]  == "Register"){
				return true;
			}
			return false;
		}
				
		public function DidUserTryToDeletePost(){
			if(isset($_GET[$this->_deletePost]) && $_GET[$this->_deletePost]  == "true"){
				return true;
			}
			return false;
		}
			
		public function DidUserTryToEditPost(){
			if(isset($_GET[$this->_editPost]) && $_GET[$this->_editPost]  == "true"){
				return true;
			}
			return false;
		}
		
		public function DidUserTryToDeleteTopic(){
				if(isset($_GET[$this->_activeController]) && $_GET[$this->_activeController]  == "DeleteTopic"){
				return true;
			}
			return false;
		}
		
		public function DidUserTryToChangeSticky(){
			if(isset($_GET[$this->_activeController]) && $_GET[$this->_activeController] == "MakeSticky"){
				return true;
			}
			return false;
		}
		
		
		public function StayAtNewTopic(){
			$_GET[$this->_activeController] = "NewTopic";
			return false;
		}
		
		public function StayAtWritePrivateMessage(){
			$_GET[$this->_writePM] = "True";
			return false;
		}
		
		public function SetActiveTopic($topicid)
		{
			$_GET[$this->_activeTopic] = $topicid;
			return false;
		}
		
		public function IsNewTopicControllerActive(){
			if(isset($_GET[$this->_activeController]) && $_GET[$this->_activeController]  == "NewTopic"){
				return true;
			}
			return false;
		}
		
		public function IsUserOptionsControllerActive(){
			if(isset($_GET[$this->_activeController]) && $_GET[$this->_activeController]  == "UserOptions"){
				return true;
			}
			return false;
		}
		public function IsUserTryingToWriteMessage(){
			if(isset($_GET[$this->_writePM]) && $_GET[$this->_writePM]  == "True"){
				return true;
			}
			return false;
		}
		public function IsSentActive(){
			if(isset($_GET[$this->_activePage]) && $_GET[$this->_activePage]  == "Sent"){
				return true;
			}
			return false;
		}
		
		public function GetActivePost(){
			if(isset($_GET[$this->_activePost])){
				return $_GET[$this->_activePost];
			}
			return false;
		}
		
		public function GetActivePM(){
			if(isset($_GET[$this->_activePM])){
				return $_GET[$this->_activePM];
			}
			return false;
		}
		
		public function GetActiveTopic(){
			if(isset($_GET[$this->_activeTopic])){
				return $_GET[$this->_activeTopic];
			}
			return false;
		}
		
		public function GetActiveCategory(){
			if(isset($_GET[$this->_activeCategory])){
				return $_GET[$this->_activeCategory];
			}
			return false;
		}
		
		public function GetActiveCategoryString(){
			return $this->_activeCategory;
		}
		
		public function GetActivePostString(){
			return $this->_activePost;
		}
		
		public function GetActiveTopicString(){
			return $this->_activeTopic;
		}
		
		public function GetActiveControllerString(){
			return $this->_activeController;
		}
		
		public function GetActivePage(){
			if(isset($_GET[$this->_activePage])){
				return $_GET[$this->_activePage];
			}
			return false;
		}
		public function GetTopicToEdit(){
			if(isset($_GET[$this->_topicToEdit])){
				return $_GET[$this->_topicToEdit];
			}
			return false;
		}
		
		public function GetActivePageString(){
			return $this->_activePage;
		}
		
		public function DrawCategoryPageLinks($categoryid,$numberOfPages,$activePage){
			$output = null;
			
			for ($i=1; $i < $numberOfPages+1 ; $i++) {
				if($i == $activePage)
				{
					$output .= "<div class=button><div class=bold><a href='index.php?$this->_activeCategory=$categoryid&$this->_activePage=$i'>$i</a></div></div>";
				}
				else{
					$output .= "<div class=button><a href='index.php?$this->_activeCategory=$categoryid&$this->_activePage=$i'>$i</a></div>";
				}
			}
			return $output;
		}
		
		public function DrawTopicPageLinks($topicid,$numberOfPages,$activePage){
			$output = null;
			
			for ($i=1; $i < $numberOfPages+1 ; $i++) {
				if($i == $activePage)
				{
					$output .= "<div class=button><div class=bold><a href='index.php?$this->_activeTopic=$topicid&$this->_activePage=$i'>$i</a></div></div>";
				}
				else{
					$output .= "<div class=button><a href='index.php?$this->_activeTopic=$topicid&$this->_activePage=$i'>$i</a></div>";
				}
			}
			return $output;
		}
		
		public function DrawCategoryLink($category){
			return "<a href='index.php?$this->_activeCategory=$category->_id&$this->_activePage=1'>$category->_name<a/>";		
		}
		
		public function DrawTopicLink($topic){
			$sticky = null;
			
			if($topic->_sticky == 1)
			{
				$sticky = "Sticky:";
			}
			
			return "<a href='index.php?$this->_activeTopic=$topic->_id&$this->_activePage=1'>$sticky $topic->_name<a/>";
		}
		
		public function DrawPrivateMessageTopicLink($message){
			return "<div class=bold><a href='index.php?$this->_activePM=$message->_id&$this->_activeController=UserOptions'>$message->_topic<a/></div>";
		}
		
		public function DrawLastPostLink($topicid, $postid, $page){
			return "<div class=lastpostbutton><a href='index.php?$this->_activeTopic=$topicid&$this->_activePage=$page#$postid'>--><a/></div>";
		}
		
		public function DrawBackLink(){
			return "<div class=index><div class=button><a href='index.php'>Back<a/></div></div>";
		}
		
		public function DrawBackToCategoryLink($categoryid){
			return "<div class=button><a href='index.php?$this->_activeCategory=$categoryid&$this->_activePage=1'>Back</a></div>";
		}
		
		public function DrawUserOptionsLink(){
			return "<div class=reverse><div class=button><a href='index.php?$this->_activeController=UserOptions&$this->_activePage=Recieved'>User Page</a></div></div>";
		}
		
		public function DrawWritePrivateMessageButton(){
			return "<div class=pm><div class=button><a href='index.php?$this->_activeController=UserOptions&$this->_writePM=True'>Write Private Message<a/></div></div>";
		}
		
		public function DrawSentButton(){
			if($this->IsSentActive())
			{
				return "<div class=sent><div class=button><div class=bold><a href='index.php?$this->_activeController=UserOptions&$this->_activePage=Sent'>Sent</a></div></div></div>";
			}
			return "<div class=sent><div class=button><a href='index.php?$this->_activeController=UserOptions&$this->_activePage=Sent'>Sent</a></div></div>";
		}
		
		public function DrawReceivedButton(){
			if($this->IsSentActive()){
				return "<div class=recieved><div class=button><a href='index.php?$this->_activeController=UserOptions&$this->_activePage=Reciever'>Received</a></div></div>";
			}
			return "<div class=recieved><div class=button><div class=bold><a href='index.php?$this->_activeController=UserOptions&$this->_activePage=Reciever'>Received</a></div></div></div>";
		}
		
		public function DrawDeletePostLink($post){
			$page = $this->GetActivePage();
			return "<div class=button><a href='index.php?$this->_activePost=$post->_id&$this->_deletePost=true&$this->_activeTopic=$post->_topicid&$this->_activePage=$page'>Delete post<a/></div>";
		}
		
		public function DrawEditPostLink($post) {
			$page = $this->GetActivePage();
			return "<div class=button><a href='index.php?$this->_activePost=$post->_id&$this->_editPost=true&$this->_activeTopic=$post->_topicid&$this->_activePage=$page#editpost'>Edit post<a/></div>";
		}
		
		public function DrawRemoveTopicLink($topicid){
			$page = $this->GetActivePage();
			$activeCategory = $this->GetActiveCategory();
			return "<div class=button><a href='index.php?$this->_activeController=DeleteTopic&$this->_activeCategory=$activeCategory&$this->_activePage=$page&$this->_topicToEdit=$topicid'>Delete Topic<a/></div>";
		}
		
		public function DrawMakeStickyLink($topicid){
			$page = $this->GetActivePage();
			$activeCategory = $this->GetActiveCategory();
			return "<div class=button><a href='index.php?$this->_activeController=MakeSticky&$this->_activeCategory=$activeCategory&$this->_activePage=$page&$this->_topicToEdit=$topicid'>Sticky/Unsticky Topic<a/></div>";
		}
		
		public function CreateNewTopicLink(){
			$activeCategory = $this->GetActiveCategory();
			return "<div class=button><a href='index.php?$this->_activeController=NewTopic&$this->_activeCategory=$activeCategory'>Create New Topic<a/></div>";
		}
		
	}
